import request from '@/utils/request';
import { PageResponse } from '@/interface/pages';

/**
 * 获取分页列表
 *
 * @returns Promise
 *
 * @todo 发起axios请求
 */
export const getNotifyList = (params: API.notify.PageListDto) => {
  return request<PageResponse<API.notify.EntitySchema[]>>({
    url: '/admin/notify',
    method: 'get',
    params
  });
};

/**
 * 创建
 *
 * @returns Promise
 *
 * @todo 发起axios请求
 */
export const createNotify = (data: API.notify.EntityDto) => {
  return request({
    url: `/admin/notify`,
    method: 'post',
    data
  });
};

/**
 * 修改
 *
 * @returns Promise
 *
 * @todo 发起axios请求
 */
export const updateNotify = (id: number, data: API.notify.EntityDto) => {
  return request({
    url: `/admin/notify/${id}`,
    method: 'put',
    data
  });
};

/**
 * 更新switch状态
 *
 * @returns Promise
 *
 * @todo 发起axios请求
 */
export const updateSwitch = (
  id: number,
  data: { state?: boolean }
): Promise<any> => {
  return request({
    url: `/admin/notify/switch/${id}`,
    method: 'put',
    data
  });
};

/**
 * 删除
 *
 * @param id
 * @returns
 *
 * @todo 发起axios请求
 */
export const deleteNotify = (id: number): Promise<any> => {
  return request({
    url: `/admin/notify/${id}`,
    method: 'delete'
  });
};
